<template>
	<view class="help-container" @touchmove.stop.prevent="() => {}">

		<view class="subsection">
			<view class="item  " @click="changeType('selling')" :class="{'active': currentType==='selling' }">
				<view class="num">{{sellingList.length}}</view>
				<view class="text">待交易商品</view>
			</view>
			<view class="item  " @click="changeType('selled')" :class="{'active': currentType==='selled' }">
				<view class="num">{{selledList.length}}</view>
				<view class="text">已交易商品</view>
			</view>


		</view>

		<view class="card-list" v-if="currentType=== 'selling'">
			<view class="order-card" v-for="(item,index) in sellingList" :key="index">
				<goods :goodsInfo="item"></goods>
			</view>
			<emptyData v-if="!sellingList.length" :tip="'暂无待交易商品信息'"> </emptyData>

		</view>

		<view class="card-list" v-if="currentType=== 'selled'">
			<view class="order-card" v-for="(item,index) in selledList" :key="index">
				<goods :goodsInfo="item"></goods>
			</view>
			<emptyData v-if="!selledList.length" :tip="'暂无已交易商品信息'"> </emptyData>

		</view>
	</view>
</template>

<script>
	import goods from '../../components/goods.vue'
	import emptyData from '../../components/emptyData.vue'
	export default {
		components: {
			goods,
			emptyData
		},
		data() {
			return {
				currentType: 'selling',
				sellingList: [],
				selledList: [],
			};
		},
		onLoad() {
			this.getSecondList()
		},
		methods: {
			changeType(type) {
				this.currentType = type
			},
			tabChange(e) {

			},
			// 获取二手商品信息
			getSecondList() {
				this.$http('get', 'api/public/allsecondGoods/findAll', {
					success: (res) => {
						const userInfo = this.$store.getters.userInfo
						const data = res.data
						this.sellingList = data.filter(item =>
							item.goodsStatus === '0' && item.uid === userInfo.uid
						)
						this.selledList = data.filter(item =>
							item.goodsStatus === '1' && item.uid === userInfo.uid
						)
					}
				})
			},
		}
	}

</script>

<style lang="scss">
	.help-container {
		height: 100vh;
		padding: 0 15px;
	}



	.subsection {
		box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
		border-radius: 8px;
		margin: 15px 0;
		background: #fff;
		height: 80px;
		display: flex;
		align-items: center;
		padding: 0 10px;

		.item {
			flex: 1;
			height: 60px;

			display: flex;
			align-items: center;
			flex-direction: column;
			justify-content: center;

			&.active {
				background: rgb(255, 255, 255);
				box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.2);
				border-radius: 8px;

				.text {
					font-weight: 700;
				}
			}

			.num {
				font-size: 18px;
				text-align: center;
				font-weight: 700;
			}

			.text {
				text-align: center;
				font-size: 12px;
				color: rgb(51, 51, 51);
				margin-top: 10px;
			}

			&:nth-child(1) {
				.num {
					color: rgb(254, 185, 58);
				}

			}

			&:nth-child(2) {
				.num {
					color: rgb(101, 132, 247);
				}

			}

			&:nth-child(3) {
				.num {
					color: rgb(245, 63, 63);
				}

			}
		}

	}

	.card-list {
		margin-top: 10px;
		height: calc(100% - 160px);
		overflow: auto;


		.order-card:not(:last-child) {
			margin-bottom: 10px;
		}
	}


	.find-help {
		padding-left: 10px;
		width: 90px;
		height: 38px;
		position: fixed;
		bottom: 80px;
		right: 0;
		color: #fff;
		display: flex;
		background: linear-gradient(135deg, #7676ee 0%, #b064fb 100%);
		box-shadow: 0px 2px 10px #8a70f2;
		border-radius: 20px 0px 0px 20px;
		align-items: center;
		font-size: 14px;

		img {
			margin-right: 8px;
		}
	}

</style>

